/************************************************************************

								Heroes IV
					  Copyright 2001, The 3DO Company

	------------------------------------------------------------------
  						   dialog_caravan_initial.cpp

	$Header: $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "dialog_caravan_initial.h"

#include "adaptor_handler.h"
#include "bitmap_group.h"
#include "bitmap_group_cache.h"
#include "bitmap_layer.h"
#include "bitmap_layer_window.h"
#include "bound_handler.h"
#include "button.h"
#include "button_cache.h"
#include "external_string.h"
#include "interface_help.h"
#include "override_input_handler.h"
#include "standard_fonts.h"
#include "text_window.h"

extern t_button_cache const		k_close_button;

namespace
{
	// hotkey resource strings
	t_external_string const k_hot_key_create( "create.hot_keys" );		// C
	t_external_string const k_hot_key_view( "view.hot_keys" );			// V
	t_external_string const k_hot_key_arrived( "arrived.hot_keys" );	// M

	t_external_string const k_caravan_initial_title( "caravan_initial.title" );
	t_external_string const k_caravan_initial_text( "caravan_initial.text" );
	t_external_string const k_caravan_initial_create_text( "caravan_initial.create_text" );
	t_external_string const k_caravan_initial_view_text( "caravan_initial.view_text" );
	t_external_string const k_caravan_initial_arrived_text( "caravan_initial.arrived_text" );
	t_bitmap_group_cache const k_bitmaps( "dialog.caravan_initial" );
}

t_dialog_caravan_initial::t_dialog_caravan_initial( t_window * parent )
	: t_window( k_completely_transparent, parent )
{
	t_help_block const& help = get_help_block( "caravan_initial" );

	m_bitmaps = k_bitmaps.get();

	t_bitmap_layer const * layer;
	t_window *             background;
	t_text_window *		   text_window;
	t_button *			   button;

	layer = m_bitmaps->find( "background" );
	background = new t_bitmap_layer_window( layer, t_screen_point(0, 0), this );

	layer = m_bitmaps->find( "title" );
	text_window = new t_text_window( get_font( 20 ), layer->get_rect(), background, k_caravan_initial_title, t_pixel_24(0,0,0) );
	text_window->set_drop_shadow( false );
	text_window->set_justification( k_justify_center );

	layer = m_bitmaps->find( "text" );
	text_window = new t_text_window( get_font( 18 ), layer->get_rect(), background, k_caravan_initial_text, t_pixel_24(0,0,0) );
	text_window->set_drop_shadow( false );
	text_window->set_justification( k_justify_center );

	layer = m_bitmaps->find( "create_text" );
	text_window = new t_text_window( get_font( 18 ), layer->get_rect(), background, k_caravan_initial_create_text, t_pixel_24(0,0,0) );
	text_window->set_drop_shadow( false );
	text_window->set_justification( k_justify_center );

	layer = m_bitmaps->find( "view_text" );
	text_window = new t_text_window( get_font( 18 ), layer->get_rect(), background, k_caravan_initial_view_text, t_pixel_24(0,0,0) );
	text_window->set_drop_shadow( false );
	text_window->set_justification( k_justify_center );

	layer = m_bitmaps->find( "arrived_text" );
	text_window = new t_text_window( get_font( 18 ), layer->get_rect(), background, k_caravan_initial_arrived_text, t_pixel_24(0,0,0) );
	text_window->set_drop_shadow( false );
	text_window->set_justification( k_justify_center );

	button = create_button( m_bitmaps, "create", background );
	button->set_click_handler( add_2nd_argument( bound_handler( *this, &t_dialog_caravan_initial::on_button ), k_result_create ) );
	set_help( button, help, "create" );

	button = create_button( m_bitmaps, "view", background );
	button->set_click_handler( add_2nd_argument( bound_handler( *this, &t_dialog_caravan_initial::on_button ), k_result_view ) );
	set_help( button, help, "view" );	

	button = create_button( m_bitmaps, "arrived", background );
	button->set_click_handler( add_2nd_argument( bound_handler( *this, &t_dialog_caravan_initial::on_button ), k_result_arrivals ) );
	set_help( button, help, "arrived" );	

	layer = m_bitmaps->find( "close_button" );
	button = new t_button( k_close_button.get(), layer->get_rect().top_left(), background );
	button->set_click_handler( add_2nd_argument( bound_handler( *this, &t_dialog_caravan_initial::on_button ), k_result_cancel ) );
	
	t_screen_rect rect = m_bitmaps->get_rect();
	rect += (parent->get_client_rect().size() - rect.size()) / 2;
	init( rect );
}

// ---------------------------------------------------------------------------
// Handle any button click
// ---------------------------------------------------------------------------
void t_dialog_caravan_initial::on_button( t_button *, t_result result )
{
	m_return_value = result;

	close();
}
